package com.christina.engine.context.model;

import com.christina.engine.intent.model.Intent;
import lombok.Data;
import lombok.Builder;
import java.time.LocalDateTime;
import java.util.List;
import java.util.Map;

/**
 * 对话上下文模型
 * 
 * @author Christina
 */
@Data
@Builder
public class ConversationContext {
    
    /**
     * 会话ID
     */
    private String sessionId;
    
    /**
     * 用户ID
     */
    private Long userId;
    
    /**
     * 对话历史
     */
    private List<ConversationTurn> conversationHistory;
    
    /**
     * 当前话题
     */
    private String currentTopic;
    
    /**
     * 对话状态
     */
    private ConversationState state;
    
    /**
     * 待处理的任务
     */
    private List<PendingTask> pendingTasks;
    
    /**
     * 会话变量
     */
    private Map<String, Object> sessionVariables;
    
    /**
     * 会话开始时间
     */
    private LocalDateTime startTime;
    
    /**
     * 最后活跃时间
     */
    private LocalDateTime lastActiveTime;
    
    /**
     * 会话过期时间
     */
    private LocalDateTime expireTime;
    
    /**
     * 对话轮次
     */
    @Data
    @Builder
    public static class ConversationTurn {
        private String userInput;
        private String assistantResponse;
        private Intent recognizedIntent;
        private Map<String, Object> extractedParameters;
        private LocalDateTime timestamp;
        private Double satisfactionScore;
    }
    
    /**
     * 对话状态
     */
    public enum ConversationState {
        ACTIVE("活跃中"),
        WAITING_INPUT("等待输入"),
        PROCESSING("处理中"),
        WAITING_CONFIRMATION("等待确认"),
        COMPLETED("已完成"),
        EXPIRED("已过期"),
        ERROR("错误状态");
        
        private final String description;
        
        ConversationState(String description) {
            this.description = description;
        }
        
        public String getDescription() {
            return description;
        }
    }
    
    /**
     * 待处理任务
     */
    @Data
    @Builder
    public static class PendingTask {
        private String taskId;
        private String taskType;
        private String description;
        private Map<String, Object> parameters;
        private TaskStatus status;
        private LocalDateTime createTime;
        private LocalDateTime dueTime;
    }
    
    /**
     * 任务状态
     */
    public enum TaskStatus {
        PENDING("待处理"),
        IN_PROGRESS("处理中"),
        COMPLETED("已完成"),
        FAILED("失败"),
        CANCELLED("已取消");
        
        private final String description;
        
        TaskStatus(String description) {
            this.description = description;
        }
        
        public String getDescription() {
            return description;
        }
    }
}